setwd("~/PRQ_contribution_access")
library(tidyverse)
library(ggpubr)
library(scales)
library(gtools)
library(ggeffects)
library(rms)
library(stargazer)
library(pastecs)
library(lmtest)
library(sandwich)

load("legislator_registrant_year_data.RData")
load("legislator_registrant_year_subset_with_ideology.RData")

#### MANUSCRIPT ####

#### Table 1 ####
attach(legislator_registrant_year_data)
table(contribution,
      access != "0_access_not_requested",
      senator)
table(contribution,
      access != "0_access_not_requested",
      senator) %>%
  prop.table(margin = c(1, 3))
detach()

#### Table 2 ####
m2.1 <- ols((access != "0_access_not_requested") ~ contribution + registrant.id + year,
            x = T, y = T,
            legislator_registrant_year_data %>%
              filter(year %in% 2016:2019)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2016:2019) %>%
           pull(legislator.id))
m2.2 <- ols((access != "0_access_not_requested") ~ contribution * close_race +
              republican + senator + majority +
              leadership + power_committee + foreign_affairs_committee +
              registrant.id + year,
            x = T, y = T,
            legislator_registrant_year_data %>%
              filter(year %in% 2016:2019)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2016:2019) %>%
           pull(legislator.id))
m2.3 <- ols((access != "0_access_not_requested") ~ contribution * close_race +
              republican + senator + majority +
              leadership + power_committee + foreign_affairs_committee +
              registrant.id + year,
            x = T, y = T,
            legislator_registrant_year_data %>%
              filter(year %in% 2016:2019,
                     number_of_lobbyists == 1)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2016:2019,
                  number_of_lobbyists == 1) %>%
           pull(legislator.id))

stargazer(m2.1, m2.2, m2.3,
          dep.var.labels = "Requested Access",
          column.separate = c(2, 1),
          column.labels = c("All Dyads", "Solo Subset"),
          omit = "registrant.id.*|year.*",
          covariate.labels = c("Contribution", "Close race", "Republican", "Senator", "Majority", "Leadership", "Power committee", "Foreign affairs committee", "Contribution x Close race"),
          add.lines = list(c("Registrant (lobbyist) FE", "Y", "Y", "Y"),
                           c("Year FE", "Y", "Y", "Y")),
          star.cutoffs = c(0.05), star.char = c("*"), df = F,
          notes = "*p$<$.05", notes.append = F, style = "ajps",
          type = "text")

#### Table 3 ####
attach(legislator_registrant_year_data %>%
         filter(access != "0_access_not_requested"))
table(contribution,
      access != "1_access_requested_unsuccessfully",
      senator)
table(contribution,
      access != "1_access_requested_unsuccessfully",
      senator) %>%
  prop.table(margin = c(1, 3))
detach()

#### Figure 4 ####
demand_for_access_house <- legislator_registrant_year_data %>%
  filter(senator == 0) %>%
  group_by(legislator.id, year) %>%
  summarise(number_of_access_seekers = n_distinct(registrant.id[access != "0_access_not_requested"])) %>%
  ungroup() %>%
  group_by(year) %>%
  summarise(demand = mean(number_of_access_seekers)) %>%
  ungroup()

demand_for_access_senate <- legislator_registrant_year_data %>%
  filter(senator == 1) %>%
  group_by(legislator.id, year) %>%
  summarise(number_of_access_seekers = n_distinct(registrant.id[access != "0_access_not_requested"])) %>%
  ungroup() %>%
  group_by(year) %>%
  summarise(demand = mean(number_of_access_seekers)) %>%
  ungroup()

pct_requests_successful_house <- legislator_registrant_year_data %>%
  filter(senator == 0) %>%
  group_by(year, contribution) %>%
  summarise(n_members_requested_access_to = sum(access != "0_access_not_requested"),
            n_members_obtained_access_to = sum(access %in% c("2_access_obtained_to_staff",
                                                             "3_access_obtained_to_member"))) %>%
  ungroup() %>%
  mutate(success_rate = n_members_obtained_access_to / n_members_requested_access_to)

pct_requests_successful_senate <- legislator_registrant_year_data %>%
  filter(senator == 1) %>%
  group_by(year, contribution) %>%
  summarise(n_members_requested_access_to = sum(access != "0_access_not_requested"),
            n_members_obtained_access_to = sum(access %in% c("2_access_obtained_to_staff",
                                                             "3_access_obtained_to_member"))) %>%
  ungroup() %>%
  mutate(success_rate = n_members_obtained_access_to / n_members_requested_access_to)

fig_success_rate_house <- ggplot(pct_requests_successful_house,
                                 aes(x = year, y = success_rate * 100,
                                     linetype = as.factor(contribution),
                                     group = as.factor(contribution))) +
  geom_line(size = 1) +
  scale_y_continuous(limits = c(0, 100)) +
  scale_linetype_manual(name = "Contributed to Campaign",
                        labels = c("No", "Yes"),
                        values = c("dashed", "solid")) +
  annotate(geom = "text", x = 17, y = 50, label = "Contributed to campaign", angle = -20) +
  annotate(geom = "text", x = 8, y = 41, label = "Did not contribute", angle = -20) +
  labs(x = "Year", y = "% Legislators Successfully Accessed", title = "House") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, size = 8, hjust = 1),
        legend.position = "none")

fig_demand_house <- ggplot(demand_for_access_house,
                           aes(x = year, y = demand, group = 1)) +
  geom_line(size = 1) +
  labs(x = "Year", y = "Access-Seeking Registrants Per Legislator") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, size = 8, hjust = 1))

fig_success_rate_senate <- ggplot(pct_requests_successful_senate,
                                  aes(x = year, y = success_rate * 100,
                                      linetype = as.factor(contribution),
                                      group = as.factor(contribution))) +
  geom_line(size = 1) +
  scale_y_continuous(limits = c(0, 100)) +
  scale_linetype_manual(name = "Contributed to Campaign",
                        labels = c("No", "Yes"),
                        values = c("dashed", "solid")) +
  annotate(geom = "text", x = 17, y = 44, label = "Contributed to campaign", angle = -20) +
  annotate(geom = "text", x = 4, y = 20, label = "Did not contribute", angle = 0) +
  labs(x = "Year", y = "% Legislators Successfully Accessed", title = "Senate") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, size = 8, hjust = 1),
        legend.position = "none")

fig_demand_senate <- ggplot(demand_for_access_senate,
                            aes(x = year, y = demand, group = 1)) +
  geom_line(size = 1) +
  labs(x = "Year", y = "Access-Seeking Registrants Per Legislator") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, size = 8, hjust = 1))

ggarrange(fig_success_rate_house, fig_success_rate_senate,
          fig_demand_house, fig_demand_senate, 
          nrow = 2, ncol = 2, common.legend = T, legend = "none")

#### Table 4 ####
m4.1 <- ols((access %in% c("2_access_obtained_to_staff",
                           "3_access_obtained_to_member")) ~
              contribution * close_race +
              republican + senator + majority +
              leadership + power_committee + foreign_affairs_committee +
              registrant.id + year,
            x = T, y = T,
            legislator_registrant_year_data %>%
              filter(access != "0_access_not_requested")) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(access != "0_access_not_requested") %>%
           pull(legislator.id))
m4.2 <- ols((access == "3_access_obtained_to_member") ~
              contribution * close_race +
              republican + senator + majority +
              leadership + power_committee + foreign_affairs_committee +
              registrant.id + year,
            x = T, y = T,
            legislator_registrant_year_data %>%
              filter(access %in% c("2_access_obtained_to_staff",
                                   "3_access_obtained_to_member"))) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(access %in% c("2_access_obtained_to_staff",
                                "3_access_obtained_to_member")) %>%
           pull(legislator.id))
m4.3 <- ols((access %in% c("2_access_obtained_to_staff",
                           "3_access_obtained_to_member")) ~ 
              contribution * close_race +
              republican + senator + majority +
              leadership + power_committee + foreign_affairs_committee +
              registrant.id + year,
            x = T, y = T,
            legislator_registrant_year_data %>%
              filter(access != "0_access_not_requested",
                     number_of_lobbyists == 1)) %>%
  robcov(legislator_registrant_year_data %>%
           filter(access != "0_access_not_requested",
                  number_of_lobbyists == 1) %>%
           pull(legislator.id))
m4.4 <- ols((access == "3_access_obtained_to_member") ~
              contribution * close_race +
              republican + senator + majority +
              leadership + power_committee + foreign_affairs_committee +
              registrant.id + year,
            x = T, y = T,
            legislator_registrant_year_data %>%
              filter(access %in% c("2_access_obtained_to_staff",
                                   "3_access_obtained_to_member"),
                     number_of_lobbyists == 1))

stargazer(m4.1, m4.2, m4.3, m4.4,
          dep.var.labels = c("Gained Access", "Personal Access", "Gained Access", "Personal Access"),
          column.labels = c("All Dyads", "Solo Subset"),
          column.separate = c(2, 2),
          omit = "registrant.id.*|year.*",
          covariate.labels = c("Contribution", "Close race", "Republican", "Senator", "Majority", "Leadership", "Power committee", "Foreign affairs committee", "Contribution x Close race"),
          add.lines = list(c("Registrant (lobbyist) FE", "Y", "Y", "Y", "Y"),
                           c("Year FE", "Y", "Y", "Y", "Y")),
          star.cutoffs = c(0.05), star.char = c("*"), df = F,
          notes = "*p$<$.05", notes.append = F, style = "ajps",
          type = "text")

#### Table 5 ####
attach(legislator_registrant_year_subset_with_ideology %>%
         filter(access != "0_access_not_requested"))
table(contribution,
      access != "1_access_requested_unsuccessfully",
      copartisan)
table(contribution,
      access != "1_access_requested_unsuccessfully",
      copartisan) %>%
  prop.table(margin = c(1, 3))
detach()

#### Figure 5 ####
fig_success_rate_same_party <- legislator_registrant_year_subset_with_ideology %>%
  filter(copartisan == 1) %>%
  group_by(year) %>%
  mutate(ideological_quantile = ideological_distance %>%
           quantcut(5) %>% as.numeric) %>%
  ungroup() %>%
  group_by(ideological_quantile,
           contribution) %>%
  summarise(n_members_requested_access_to = sum(access != "0_access_not_requested"),
            n_members_obtained_access_to = sum(access %in% c("2_access_obtained_to_staff",
                                                             "3_access_obtained_to_member"))) %>%
  ungroup() %>%
  mutate(success_rate = n_members_obtained_access_to / n_members_requested_access_to) %>%
  na.omit() %>%
  ggplot() +
  geom_line(aes(x = ideological_quantile, y = success_rate * 100,
                linetype = factor(contribution)),
            size = 1) +
  annotate(geom = "text", x = 2, y = 55, label = "Contributed to campaign") +
  annotate(geom = "text", x = 2, y = 15, label = "Did not contribute") +
  labs(title = "Same Party",
       x = "Ideological Distance (Quintiles)", y = "% Members of Congress Successfully Accessed") +
  lims(y = c(0, 100)) +
  theme_bw() +
  theme(legend.key.size = unit(3, "line"), legend.position = "none")

fig_success_rate_opposing_party <- legislator_registrant_year_subset_with_ideology %>%
  filter(copartisan == 0) %>%
  group_by(year) %>%
  mutate(ideological_quantile = ideological_distance %>%
           quantcut(5) %>% as.numeric) %>%
  ungroup() %>%
  group_by(ideological_quantile,
           contribution) %>%
  summarise(n_members_requested_access_to = sum(access != "0_access_not_requested"),
            n_members_obtained_access_to = sum(access %in% c("2_access_obtained_to_staff",
                                                             "3_access_obtained_to_member"))) %>%
  ungroup() %>%
  mutate(success_rate = n_members_obtained_access_to / n_members_requested_access_to) %>%
  na.omit() %>%
  ggplot() +
  geom_line(aes(x = ideological_quantile, y = success_rate * 100,
                linetype = factor(contribution)),
            size = 1) +
  annotate(geom = "text", x = 2, y = 85, label = "Did not contribute") +
  annotate(geom = "text", x = 2, y = 45, label = "Contributed to campaign") +
  labs(title = "Opposing Party",
       x = "Ideological Distance (Quintiles)", y = "% Members of Congress Successfully Accessed") +
  lims(y = c(0, 100)) +
  theme_bw() +
  theme(legend.key.size = unit(3, "line"), legend.position = "none")

ggarrange(fig_success_rate_same_party, fig_success_rate_opposing_party,
          nrow = 1, ncol = 2, common.legend = T, legend = "none")

#### Table 6 ####
m6.1 <- ols((access %in% c("2_access_obtained_to_staff", 
                           "3_access_obtained_to_member")) ~ 
              contribution * ideological_distance +
              republican + senator + majority + leadership +
              power_committee + foreign_affairs_committee +
              number_of_clients + year,
            x = T, y = T,
            legislator_registrant_year_subset_with_ideology %>%
              filter(access != "0_access_not_requested")) %>%
  robcov(cluster = legislator_registrant_year_subset_with_ideology %>%
           filter(access != "0_access_not_requested") %>%
           pull(legislator.id))
m6.2 <- ols((access %in% c("2_access_obtained_to_staff", 
                           "3_access_obtained_to_member")) ~ 
              contribution * ideological_distance +
              republican + senator + majority + leadership +
              power_committee + foreign_affairs_committee +
              number_of_clients + year,
            x = T, y = T,
            legislator_registrant_year_subset_with_ideology %>%
              filter(access != "0_access_not_requested",
                     copartisan == 1)) %>%
  robcov(cluster = legislator_registrant_year_subset_with_ideology %>%
           filter(access != "0_access_not_requested",
                  copartisan == 1) %>%
           pull(legislator.id))
m6.3 <- ols((access == "3_access_obtained_to_member") ~
              contribution * ideological_distance + 
              republican + senator + majority +
              leadership + power_committee + foreign_affairs_committee +
              number_of_clients + year,
            x = T, y = T,
            legislator_registrant_year_subset_with_ideology %>%
              filter(access %in% c("2_access_obtained_to_staff",
                                   "3_access_obtained_to_member"))) %>%
  robcov(cluster = legislator_registrant_year_subset_with_ideology %>%
           filter(access %in% c("2_access_obtained_to_staff",
                                "3_access_obtained_to_member")) %>%
           pull(legislator.id))
m6.4 <- ols((access == "3_access_obtained_to_member") ~
              contribution * ideological_distance + 
              republican + senator + majority +
              leadership + power_committee + foreign_affairs_committee +
              number_of_clients + year,
            x = T, y = T,
            legislator_registrant_year_subset_with_ideology %>%
              filter(access %in% c("2_access_obtained_to_staff",
                                   "3_access_obtained_to_member"),
                     copartisan == 1)) %>%
  robcov(cluster = legislator_registrant_year_subset_with_ideology %>%
           filter(access %in% c("2_access_obtained_to_staff",
                                "3_access_obtained_to_member"),
                  copartisan == 1) %>%
           pull(legislator.id))

stargazer(m6.1, m6.2, m6.3, m6.4,
          dep.var.labels = c("Gained Access", "Personal Access"),
          column.labels = c("All Legislators", "Copartisans", "All Legislators", "Copartisans"),
          omit = "registrant.id*|year.*",
          covariate.labels = c("Contribution", "Ideological distance", "Republican", "Senator", "Majority", "Leadership", "Power committee", "Foreign affairs committee", "Number of clients", "Contribution x Ideological distance"),
          add.lines = list(c("Year FE", "Y", "Y", "Y", "Y")),
          star.cutoffs = c(0.05), star.char = c("*"), df = F,
          notes = "*p$<$.05", notes.append = F, style = "ajps",
          type = "text")

#### Figure 6 ####
m.logit <- glm(as.numeric(access %in% c("2_access_obtained_to_staff",
                                        "3_access_obtained_to_member")) ~
                 contribution * ideological_distance +
                 republican + senator + majority +
                 leadership + power_committee + foreign_affairs_committee +
                 number_of_clients + year,
               family = binomial(link = "logit"),
               legislator_registrant_year_subset_with_ideology %>%
                 filter(access != "0_access_not_requested"))

attach(legislator_registrant_year_subset_with_ideology %>%
         filter(access != "0_access_not_requested"))
newdata <- tibble(republican = table(republican) %>%
                    sort(decreasing = T) %>% names() %>% .[1],
                  senator = 0,
                  majority = 1,
                  leadership = 0,
                  power_committee = 0,
                  foreign_affairs_committee = 0,
                  number_of_clients = mean(number_of_clients, na.rm = T),
                  year = year[1])
detach()
v <- seq(0,
         max(legislator_registrant_year_subset_with_ideology$ideological_distance, na.rm = T), .02)

predicted_probabilities <- ggpredict(m.logit, c("contribution", "ideological_distance [v]"),
                                     condition = c(republican = newdata$republican,
                                                   senator = newdata$senator,
                                                   majority = newdata$majority,
                                                   leadership = newdata$leadership,
                                                   power_committee = newdata$power_committee,
                                                   foreign_affairs_committee = newdata$foreign_affairs_committee,
                                                   number_of_clients = newdata$number_of_clients,
                                                   year = newdata$year)) %>%
  tibble() %>%
  mutate(ideological_distance = as.numeric(paste(group)))

ggplot(predicted_probabilities,
       aes(x = ideological_distance, y = predicted, linetype = factor(x))) +
  geom_line(size = 1) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high, fill = factor(x)),
              alpha = .3, show.legend = F) +
  scale_linetype_manual(name = "Contributed to Campaign",
                        labels = c("No", "Yes"),
                        values = c("dashed", "solid")) +
  annotate(geom = "text", x = .4, y = .35, label = "Contributed to campaign", size = 3) +
  annotate(geom = "text", x = 1.25, y = .25, label = "Did not contribute", size = 3) +
  scale_y_continuous(labels = percent) +
  labs(x = "Ideological Distance (DW-NOMINATE, 1st Dimension)",
       y = "Predicted Probability of Gaining Access") +
  theme_bw() +
  theme(legend.position = "none")

#### SUPPLEMENTAL MATERIALS ####

#### Appendix B (Descriptive Statistics) ####
# For Table 2
d <- legislator_registrant_year_data %>%
  filter(year %in% 2016:2019) %>%
  mutate(requested_access = as.numeric(access != "0_access_not_requested")) %>%
  select('Requested access' = requested_access,
         'Contribution' = contribution,
         'Close race' = close_race, 
         'Republican' = republican,
         'Senator' = senator, 
         'Majority' = majority,
         'Leadership' = leadership,
         'Power committee' = power_committee,
         'Foreign affairs committee' = foreign_affairs_committee) %>%
  na.omit()

stat.desc(d) %>% t() %>%
  as_tibble() %>%
  mutate(Variable = names(d),
         Type = "Binary") %>%
  select(Variable, Type, Min = min, Max = max, Mean = mean, 'Std. Dev.' = std.dev) %>%
  mutate_at(vars(Min:'Std. Dev.'), function(x) round(x, digits = 2)) %>%
  stargazer(summary = F, rownames = F, type = "text")

# For Table 4
d <- legislator_registrant_year_data %>%
  filter(access != "0_access_not_requested") %>%
  mutate(gained_access = as.numeric(access %in% c("2_access_obtained_to_staff",
                                                  "3_access_obtained_to_member")),
         personal_access = as.numeric(access == "3_access_obtained_to_member")) %>%
  select('Gained access' = gained_access,
         'Personal access' = personal_access,
         'Contribution' = contribution,
         'Close race' = close_race, 
         'Republican' = republican,
         'Senator' = senator, 
         'Majority' = majority,
         'Leadership' = leadership,
         'Power committee' = power_committee,
         'Foreign affairs committee' = foreign_affairs_committee) %>%
  na.omit()

stat.desc(d) %>% t() %>%
  as_tibble() %>%
  mutate(Variable = names(d),
         Type = c(rep("Binary", 10))) %>%
  select(Variable, Type, Min = min, Max = max, Mean = mean, 'Std. Dev.' = std.dev) %>%
  mutate_at(vars(Min:'Std. Dev.'), function(x) round(x, digits = 2)) %>%
  stargazer(summary = F, rownames = F, type = "text")

# For Table 6
d <- legislator_registrant_year_subset_with_ideology %>%
  filter(access != "0_access_not_requested") %>%
  mutate(gained_access = as.numeric(access %in% c("2_access_obtained_to_staff",
                                                  "3_access_obtained_to_member")),
         personal_access = as.numeric(access == "3_access_obtained_to_member")) %>%
  select('Gained access' = gained_access,
         'Personal access' = personal_access,
         'Contribution' = contribution,
         'Ideological distance' = ideological_distance, 
         'Republican' = republican,
         'Senator' = senator, 
         'Majority' = majority,
         'Leadership' = leadership,
         'Power committee' = power_committee,
         'Foreign affairs committee' = foreign_affairs_committee,
         'Number of clients' = number_of_clients) %>%
  na.omit()

stat.desc(d) %>% t() %>%
  as_tibble() %>%
  mutate(Variable = names(d),
         Type = c(rep("Binary", 3), "Numeric", rep("Binary", 7))) %>%
  select(Variable, Type, Min = min, Max = max, Mean = mean, 'Std. Dev.' = std.dev) %>%
  mutate_at(vars(Min:'Std. Dev.'), function(x) round(x, digits = 2)) %>%
  stargazer(summary = F, rownames = F, type = "text")

#### Appendix D.1 (Logit Regressions) ####
mD.1.1 <- glm((access != "0_access_not_requested") ~ contribution * close_race +
                republican + senator + majority +
                leadership + power_committee + foreign_affairs_committee +
                registrant.id + year,
              family = binomial(link = "logit"),
              legislator_registrant_year_data %>%
                filter(year %in% 2016:2019))
rse.mD.1.1 <- coef_test(mD.1.1, vcov = "CR1",
                        cluster = legislator_registrant_year_data %>%
                          filter(year %in% 2016:2019) %>%
                          pull(legislator.id),
                        test = "naive-t")$SE
mD.1.2 <- glm((access %in% c("2_access_obtained_to_staff",
                             "3_access_obtained_to_member")) ~
                contribution * close_race +
                republican + senator + majority +
                leadership + power_committee + foreign_affairs_committee +
                registrant.id + year,
              family = binomial(link = "logit"),
              legislator_registrant_year_data %>%
                filter(access != "0_access_not_requested"))
rse.mD.1.2 <- coeftest(mD.1.2,
                       vcov = vcovHC(mD.1.2, type="HC1", cluster="icpsr"))[, "Std. Error"]

mD.1.3 <- glm((access %in% c("2_access_obtained_to_staff", 
                             "3_access_obtained_to_member")) ~ 
                contribution * ideological_distance +
                republican + senator + majority + leadership +
                power_committee + foreign_affairs_committee +
                number_of_clients + year,
              family = binomial(link = "logit"),
              legislator_registrant_year_subset_with_ideology %>%
                filter(access != "0_access_not_requested"))
rse.mD.1.3 <- coeftest(mD.1.3,
                       vcov = vcovHC(mD.1.3, type="HC1", cluster="icpsr"))[, "Std. Error"]

mD.1.4 <- glm((access == "3_access_obtained_to_member") ~
                contribution * ideological_distance + 
                republican + senator + majority +
                leadership + power_committee + foreign_affairs_committee +
                number_of_clients + year,
              family = binomial(link = "logit"),
              legislator_registrant_year_subset_with_ideology %>%
                filter(access %in% c("2_access_obtained_to_staff",
                                     "3_access_obtained_to_member")))
rse.mD.1.4 <- coeftest(mD.1.4,
                       vcov = vcovHC(mD.1.4, type="HC1", cluster="icpsr"))[, "Std. Error"]

stargazer(mD.1.1, mD.1.2, mD.1.3, mD.1.4,
          se = list(rse.mD.1.1, rse.mD.1.2, rse.mD.1.3, rse.mD.1.4),
          dep.var.labels = c("Request for Access", "Gaining Access", "Personal Access"),
          omit = "registrant.id.*|year.*",
          covariate.labels = c("Contribution", "Close race", "Ideological distance", "Republican", "Senator", "Majority", "Leadership", "Power committee", "Foreign affairs committee", "Number of Clients", "Contribution x Close Race", "Contribution x Ideological distance"),
          add.lines = list(c("Registrant (Lobbyist) FE", "Y", "Y", "N", "N"),
                           c("Year FE", "Y", "Y", "Y", "Y")),
          star.cutoffs = c(0.05), star.char = c("*"), df = F,
          notes = "*p$<$.05", notes.append = F, style = "ajps",
          type = "text")

#### Appendix D.5 (Access-Seeking Regressions Over Different Years) ####
mD.5.2004 <- ols((access != "0_access_not_requested") ~ contribution * close_race +
                   republican + senator + majority +
                   leadership + power_committee + foreign_affairs_committee +
                   registrant.id + year,
                 x = T, y = T,
                 legislator_registrant_year_data %>%
                   filter(year %in% 2004:2007)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2004:2007) %>%
           pull(legislator.id))
mD.5.2004.solo <- ols((access != "0_access_not_requested") ~ contribution * close_race +
                        republican + senator + majority +
                        leadership + power_committee + foreign_affairs_committee +
                        registrant.id + year,
                      x = T, y = T,
                      legislator_registrant_year_data %>%
                        filter(year %in% 2004:2007,
                               number_of_lobbyists == 1)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2004:2007,
                  number_of_lobbyists == 1) %>%
           pull(legislator.id))

mD.5.2008 <- ols((access != "0_access_not_requested") ~ contribution * close_race +
                   republican + senator + majority +
                   leadership + power_committee + foreign_affairs_committee +
                   registrant.id + year,
                 x = T, y = T,
                 legislator_registrant_year_data %>%
                   filter(year %in% 2008:2011)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2008:2011) %>%
           pull(legislator.id))
mD.5.2008.solo <- ols((access != "0_access_not_requested") ~ contribution * close_race +
                        republican + senator + majority +
                        leadership + power_committee + foreign_affairs_committee +
                        registrant.id + year,
                      x = T, y = T,
                      legislator_registrant_year_data %>%
                        filter(year %in% 2008:2011,
                               number_of_lobbyists == 1)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2008:2011,
                  number_of_lobbyists == 1) %>%
           pull(legislator.id))

mD.5.2012 <- ols((access != "0_access_not_requested") ~ contribution * close_race +
                   republican + senator + majority +
                   leadership + power_committee + foreign_affairs_committee +
                   registrant.id + year,
                 x = T, y = T,
                 legislator_registrant_year_data %>%
                   filter(year %in% 2012:2015)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2012:2015) %>%
           pull(legislator.id))
mD.5.2012.solo <- ols((access != "0_access_not_requested") ~ contribution * close_race +
                        republican + senator + majority +
                        leadership + power_committee + foreign_affairs_committee +
                        registrant.id + year,
                      x = T, y = T,
                      legislator_registrant_year_data %>%
                        filter(year %in% 2012:2015,
                               number_of_lobbyists == 1)) %>%
  robcov(cluster = legislator_registrant_year_data %>%
           filter(year %in% 2012:2015,
                  number_of_lobbyists == 1) %>%
           pull(legislator.id))

stargazer(mD.5.2004, mD.5.2008, mD.5.2012,
          dep.var.labels = "Request for Access",
          column.labels = c("2004-2007", "2008-2011", "2012-2015"),
          omit = "registrant.id.*|year.*",
          covariate.labels = c("Contribution", "Close race", "Republican", "Senator", "Majority", "Leadership", "Power committee", "Foreign affairs committee", "Contribution x Close race"),
          add.lines = list(c("Registrant (lobbyist) FE", "Y", "Y", "Y"),
                           c("Year FE", "Y", "Y", "Y")),
          star.cutoffs = c(0.05), star.char = c("*"), df = F,
          notes = "*p$<$.05", notes.append = F, style = "ajps",
          type = "text")
stargazer(mD.5.2004.solo, mD.5.2008.solo, mD.5.2012.solo,
          dep.var.labels = "Request for Access",
          column.labels = c("2004-2007", "2008-2011", "2012-2015"),
          omit = "registrant.id.*|year.*",
          covariate.labels = c("Contribution", "Close race", "Republican", "Senator", "Majority", "Leadership", "Power committee", "Foreign affairs committee", "Contribution x Close race"),
          add.lines = list(c("Registrant (lobbyist) FE", "Y", "Y", "Y"),
                           c("Year FE", "Y", "Y", "Y")),
          star.cutoffs = c(0.05), star.char = c("*"), df = F,
          notes = "*p$<$.05", notes.append = F, style = "ajps",
          type = "text")